package im430.santashelper.dao.mybatis;

import im430.santashelper.business.Address;
import im430.santashelper.dao.AddressDAO;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;

public class AddressDAOImpl implements AddressDAO {

	private SqlSession sqlSession;

	public void addAddress(Address address) {
		getSqlSession().insert("im430.santashelper.dao.mybatis.AddressDAOImpl.addAddress", address);
	}

	public void updateAddress(Address address) {
		getSqlSession().update("im430.santashelper.dao.mybatis.AddressDAOImpl.updateAddress", address);
	}

	public void removeAddress(Address address) {
		getSqlSession().delete("im430.santashelper.dao.mybatis.AddressDAOImpl.removeAddress", address);
	}

	public Address getAddressById(int id) {
		return getSqlSession().selectOne("im430.santashelper.dao.mybatis.AddressDAOImpl.getAddressById", id);
	}

	public List<Address> getAllAddresses() {
		return getSqlSession().selectList("im430.santashelper.dao.mybatis.AddressDAOImpl.getAllAddresses");
	}

	public SqlSession getSqlSession() {
		return sqlSession;
	}

	@Autowired
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

}